package com.thomasbrault.display 
{
	import com.greensock.TweenLite;

	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;

	/**
	 * @author thomas
	 */
	public class GenericLoader extends Loader 
	{
		
		protected var _transitionType : String = 'none';		protected var _transitionParams : Object = null;
		
		public function GenericLoader( $url : String = null, $transitionType : String = 'none', $transitionParams : Object = null )
		{
			_transitionType = $transitionType;
			_transitionParams = $transitionParams;
			directLoad($url);
		}
		
		public function directLoad ( $url : String , $context : LoaderContext = null ) : void
		{
			contentLoaderInfo.addEventListener(Event.COMPLETE, _complete);
			super.load(new URLRequest($url),$context);
		}
		
		
		private function _complete(event : Event) : void
		{
			switch ( _transitionType )
			{
				case GenericLoaderTransitionType.ALPHA:
					var duration : Number = _transitionParams!= null && _transitionParams.duration is Number ? _transitionParams.duration : 0.5;
					TweenLite.to(this, duration, {alpha: 1});
				break;
			}
			contentLoaderInfo.removeEventListener(Event.COMPLETE, _complete);
			dispatchEvent(new Event(Event.COMPLETE));
		}
	}
}
